' cd assignment adjusted to use array of structure instead of paralelel arrays ' also, writes sales to file - to illustrate passing a structure to a procedure Option Explicit On Option Strict On Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox Friend WithEvents LstCD As System.Windows.Forms.ListBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents TxtCD As System.Windows.Forms.TextBox Friend WithEvents TxtArtist As System.Windows.Forms.TextBox Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents TxtPrice As System.Windows.Forms.TextBox Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents TxtTax As System.Windows.Forms.TextBox Friend WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents TxtTotal As System.Windows.Forms.TextBox Friend WithEvents Label7 As System.Windows.Forms.Label Friend WithEvents BtnBuy As System.Windows.Forms.Button Friend WithEvents BtnClear As System.Windows.Forms.Button Friend WithEvents TxtInv As System.Windows.Forms.TextBox Friend WithEvents Label8 As System.Windows.Forms.Label Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox Friend WithEvents BtnInv As System.Windows.Forms.Button Friend WithEvents BtnSummary As System.Windows.Forms.Button Friend WithEvents BtnQuit As System.Windows.Forms.Button Friend WithEvents TxtRev As System.Windows.Forms.TextBox Friend WithEvents Label9 As System.Windows.Forms.Label Friend WithEvents TxtTop As System.Windows.Forms.TextBox Friend WithEvents Label10 As System.Windows.Forms.Label Friend WithEvents TxtTopArtist As System.Windows.Forms.TextBox Friend WithEvents Label11 As System.Windows.Forms.Label Friend WithEvents LstInv As System.Windows.Forms.ListBox Friend WithEvents BtnInClass As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.GroupBox1 = New System.Windows.Forms.GroupBox Me.TxtInv = New System.Windows.Forms.TextBox Me.Label8 = New System.Windows.Forms.Label Me.BtnClear = New System.Windows.Forms.Button Me.BtnBuy = New System.Windows.Forms.Button Me.TxtTotal = New System.Windows.Forms.TextBox Me.Label7 = New System.Windows.Forms.Label Me.TxtTax = New System.Windows.Forms.TextBox Me.Label6 = New System.Windows.Forms.Label Me.TxtPrice = New System.Windows.Forms.TextBox Me.Label5 = New System.Windows.Forms.Label Me.TxtArtist = New System.Windows.Forms.TextBox Me.Label4 = New System.Windows.Forms.Label Me.TxtCD = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.LstCD = New System.Windows.Forms.ListBox Me.GroupBox2 = New System.Windows.Forms.GroupBox Me.LstInv = New System.Windows.Forms.ListBox Me.Label11 = New System.Windows.Forms.Label Me.TxtTopArtist = New System.Windows.Forms.TextBox Me.TxtTop = New System.Windows.Forms.TextBox Me.Label10 = New System.Windows.Forms.Label Me.TxtRev = New System.Windows.Forms.TextBox Me.Label9 = New System.Windows.Forms.Label Me.BtnInv = New System.Windows.Forms.Button Me.BtnSummary = New System.Windows.Forms.Button Me.BtnQuit = New System.Windows.Forms.Button Me.BtnInClass = New System.Windows.Forms.Button Me.GroupBox1.SuspendLayout() Me.GroupBox2.SuspendLayout() Me.SuspendLayout() ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(193, 21) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(122, 31) Me.Label1.TabIndex = 0 Me.Label1.Text = "CDs R Us" ' 'GroupBox1 ' Me.GroupBox1.Controls.Add(Me.TxtInv) Me.GroupBox1.Controls.Add(Me.Label8) Me.GroupBox1.Controls.Add(Me.BtnClear) Me.GroupBox1.Controls.Add(Me.BtnBuy) Me.GroupBox1.Controls.Add(Me.TxtTotal) Me.GroupBox1.Controls.Add(Me.Label7) Me.GroupBox1.Controls.Add(Me.TxtTax) Me.GroupBox1.Controls.Add(Me.Label6) Me.GroupBox1.Controls.Add(Me.TxtPrice) Me.GroupBox1.Controls.Add(Me.Label5) Me.GroupBox1.Controls.Add(Me.TxtArtist) Me.GroupBox1.Controls.Add(Me.Label4) Me.GroupBox1.Controls.Add(Me.TxtCD) Me.GroupBox1.Controls.Add(Me.Label3) Me.GroupBox1.Controls.Add(Me.Label2) Me.GroupBox1.Controls.Add(Me.LstCD) Me.GroupBox1.Location = New System.Drawing.Point(27, 62) Me.GroupBox1.Name = "GroupBox1" Me.GroupBox1.Size = New System.Drawing.Size(513, 340) Me.GroupBox1.TabIndex = 1 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Purchase" ' 'TxtInv ' Me.TxtInv.Location = New System.Drawing.Point(367, 146) Me.TxtInv.Name = "TxtInv" Me.TxtInv.ReadOnly = True Me.TxtInv.Size = New System.Drawing.Size(126, 20) Me.TxtInv.TabIndex = 15 Me.TxtInv.Text = "" ' 'Label8 ' Me.Label8.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label8.Location = New System.Drawing.Point(273, 146) Me.Label8.Name = "Label8" Me.Label8.Size = New System.Drawing.Size(94, 20) Me.Label8.TabIndex = 14 Me.Label8.Text = "Inventory:" ' 'BtnClear ' Me.BtnClear.Location = New System.Drawing.Point(380, 284) Me.BtnClear.Name = "BtnClear" Me.BtnClear.Size = New System.Drawing.Size(87, 35) Me.BtnClear.TabIndex = 13 Me.BtnClear.Text = "Clear" ' 'BtnBuy ' Me.BtnBuy.Location = New System.Drawing.Point(273, 284) Me.BtnBuy.Name = "BtnBuy" Me.BtnBuy.Size = New System.Drawing.Size(87, 35) Me.BtnBuy.TabIndex = 12 Me.BtnBuy.Text = "Buy" ' 'TxtTotal ' Me.TxtTotal.Location = New System.Drawing.Point(367, 222) Me.TxtTotal.Name = "TxtTotal" Me.TxtTotal.ReadOnly = True Me.TxtTotal.Size = New System.Drawing.Size(126, 20) Me.TxtTotal.TabIndex = 11 Me.TxtTotal.Text = "" ' 'Label7 ' Me.Label7.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label7.Location = New System.Drawing.Point(273, 222) Me.Label7.Name = "Label7" Me.Label7.Size = New System.Drawing.Size(94, 21) Me.Label7.TabIndex = 10 Me.Label7.Text = "Total:" ' 'TxtTax ' Me.TxtTax.Location = New System.Drawing.Point(367, 180) Me.TxtTax.Name = "TxtTax" Me.TxtTax.ReadOnly = True Me.TxtTax.Size = New System.Drawing.Size(126, 20) Me.TxtTax.TabIndex = 9 Me.TxtTax.Text = "" ' 'Label6 ' Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label6.Location = New System.Drawing.Point(273, 180) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(94, 21) Me.Label6.TabIndex = 8 Me.Label6.Text = "Tax:" ' 'TxtPrice ' Me.TxtPrice.Location = New System.Drawing.Point(367, 111) Me.TxtPrice.Name = "TxtPrice" Me.TxtPrice.ReadOnly = True Me.TxtPrice.Size = New System.Drawing.Size(126, 20) Me.TxtPrice.TabIndex = 7 Me.TxtPrice.Text = "" ' 'Label5 ' Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label5.Location = New System.Drawing.Point(273, 111) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(94, 21) Me.Label5.TabIndex = 6 Me.Label5.Text = "CD Price:" ' 'TxtArtist ' Me.TxtArtist.Location = New System.Drawing.Point(367, 76) Me.TxtArtist.Name = "TxtArtist" Me.TxtArtist.ReadOnly = True Me.TxtArtist.Size = New System.Drawing.Size(126, 20) Me.TxtArtist.TabIndex = 5 Me.TxtArtist.Text = "" ' 'Label4 ' Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.Location = New System.Drawing.Point(273, 76) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(94, 21) Me.Label4.TabIndex = 4 Me.Label4.Text = "CD Artist:" ' 'TxtCD ' Me.TxtCD.Location = New System.Drawing.Point(367, 42) Me.TxtCD.Name = "TxtCD" Me.TxtCD.ReadOnly = True Me.TxtCD.Size = New System.Drawing.Size(126, 20) Me.TxtCD.TabIndex = 3 Me.TxtCD.Text = "" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(273, 42) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(94, 20) Me.Label3.TabIndex = 2 Me.Label3.Text = "CD Title:" ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(20, 28) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(173, 21) Me.Label2.TabIndex = 1 Me.Label2.Text = "Choose CD:" ' 'LstCD ' Me.LstCD.Location = New System.Drawing.Point(20, 55) Me.LstCD.Name = "LstCD" Me.LstCD.Size = New System.Drawing.Size(227, 251) Me.LstCD.TabIndex = 0 ' 'GroupBox2 ' Me.GroupBox2.Controls.Add(Me.LstInv) Me.GroupBox2.Controls.Add(Me.Label11) Me.GroupBox2.Controls.Add(Me.TxtTopArtist) Me.GroupBox2.Controls.Add(Me.TxtTop) Me.GroupBox2.Controls.Add(Me.Label10) Me.GroupBox2.Controls.Add(Me.TxtRev) Me.GroupBox2.Controls.Add(Me.Label9) Me.GroupBox2.Location = New System.Drawing.Point(560, 69) Me.GroupBox2.Name = "GroupBox2" Me.GroupBox2.Size = New System.Drawing.Size(300, 423) Me.GroupBox2.TabIndex = 2 Me.GroupBox2.TabStop = False Me.GroupBox2.Text = "Management" ' 'LstInv ' Me.LstInv.Location = New System.Drawing.Point(27, 180) Me.LstInv.Name = "LstInv" Me.LstInv.Size = New System.Drawing.Size(260, 199) Me.LstInv.TabIndex = 10 ' 'Label11 ' Me.Label11.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label11.Location = New System.Drawing.Point(20, 146) Me.Label11.Name = "Label11" Me.Label11.Size = New System.Drawing.Size(207, 20) Me.Label11.TabIndex = 9 Me.Label11.Text = "Inventory:" ' 'TxtTopArtist ' Me.TxtTopArtist.Location = New System.Drawing.Point(140, 111) Me.TxtTopArtist.Name = "TxtTopArtist" Me.TxtTopArtist.ReadOnly = True Me.TxtTopArtist.Size = New System.Drawing.Size(127, 20) Me.TxtTopArtist.TabIndex = 8 Me.TxtTopArtist.Text = "" ' 'TxtTop ' Me.TxtTop.Location = New System.Drawing.Point(140, 83) Me.TxtTop.Name = "TxtTop" Me.TxtTop.ReadOnly = True Me.TxtTop.Size = New System.Drawing.Size(127, 20) Me.TxtTop.TabIndex = 7 Me.TxtTop.Text = "" ' 'Label10 ' Me.Label10.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label10.Location = New System.Drawing.Point(20, 83) Me.Label10.Name = "Label10" Me.Label10.Size = New System.Drawing.Size(107, 21) Me.Label10.TabIndex = 6 Me.Label10.Text = "Top Seller:" ' 'TxtRev ' Me.TxtRev.Location = New System.Drawing.Point(140, 49) Me.TxtRev.Name = "TxtRev" Me.TxtRev.ReadOnly = True Me.TxtRev.Size = New System.Drawing.Size(127, 20) Me.TxtRev.TabIndex = 5 Me.TxtRev.Text = "" ' 'Label9 ' Me.Label9.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label9.Location = New System.Drawing.Point(20, 49) Me.Label9.Name = "Label9" Me.Label9.Size = New System.Drawing.Size(107, 20) Me.Label9.TabIndex = 4 Me.Label9.Text = "Total Revenues:" ' 'BtnInv ' Me.BtnInv.Location = New System.Drawing.Point(140, 437) Me.BtnInv.Name = "BtnInv" Me.BtnInv.Size = New System.Drawing.Size(87, 34) Me.BtnInv.TabIndex = 16 Me.BtnInv.Text = "Inventory" ' 'BtnSummary ' Me.BtnSummary.Location = New System.Drawing.Point(47, 437) Me.BtnSummary.Name = "BtnSummary" Me.BtnSummary.Size = New System.Drawing.Size(86, 34) Me.BtnSummary.TabIndex = 15 Me.BtnSummary.Text = "Summary" ' 'BtnQuit ' Me.BtnQuit.Location = New System.Drawing.Point(240, 437) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.Size = New System.Drawing.Size(87, 34) Me.BtnQuit.TabIndex = 17 Me.BtnQuit.Text = "Quit" ' 'BtnInClass ' Me.BtnInClass.Location = New System.Drawing.Point(80, 24) Me.BtnInClass.Name = "BtnInClass" Me.BtnInClass.Size = New System.Drawing.Size(64, 32) Me.BtnInClass.TabIndex = 18 Me.BtnInClass.Text = "Summary" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.AutoScroll = True Me.ClientSize = New System.Drawing.Size(612, 433) Me.Controls.Add(Me.BtnInClass) Me.Controls.Add(Me.BtnQuit) Me.Controls.Add(Me.BtnInv) Me.Controls.Add(Me.BtnSummary) Me.Controls.Add(Me.GroupBox2) Me.Controls.Add(Me.GroupBox1) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.GroupBox1.ResumeLayout(False) Me.GroupBox2.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region Structure cd Public title As String Public artist As String Public price As Double Public inventory As Integer Public sold As Integer Public revenues As Double End Structure Dim inpf As IO.StreamReader Dim outpf As IO.StreamWriter Dim numCD As Integer = 0 Const arraySize As Integer = 40 Const taxRate As Double = 0.07 Dim CDs(arraySize) As cd Private Sub clearText() TxtCD.Text = "" TxtArtist.Text = "" TxtPrice.Text = "" TxtTax.Text = "" TxtInv.Text = "" TxtTotal.Text = "" End Sub ' sorts the array of cd structures based on inventory (high to low) Private Sub sortStructByInventory(ByRef array() As cd, ByVal num As Integer) Dim outer As Integer Dim inner As Integer Dim posOfLarge As Integer Dim temp As cd ' loop through all but last position of the array ' each time, place the largest remaining inventory into the current position For outer = 0 To (num - 2) posOfLarge = outer ' default to largest being first ' loop through remaining cds finding the largest inventory For inner = outer + 1 To (num - 1) If array(inner).inventory > array(posOfLarge).inventory Then ' new largest - update position of largest posOfLarge = inner End If Next inner ' determine if a swap is needed If posOfLarge <> outer Then temp = array(posOfLarge) array(posOfLarge) = array(outer) array(outer) = temp End If Next outer End Sub ' ensure that list box is in synch with array Private Sub refreshList(ByVal array() As cd, ByVal num As Integer) Dim cnt As Integer LstCD.Items.Clear() For cnt = 0 To num - 1 ' here's an idea - don't show out of stock CDs If array(cnt).inventory > 0 Then LstCD.Items.Add(array(cnt).title & " " & array(cnt).artist & " " & array(cnt).price) End If Next cnt End Sub Private Sub sortCDsNRefreshList(ByRef array() As cd, ByVal num As Integer) sortStructByInventory(array, num) refreshList(array, num) End Sub Private Sub writeSale(ByVal currCd As cd, ByVal outf As IO.StreamWriter) outf.WriteLine(currCd.title & "," & currCd.artist & "," & _ currCd.price.ToString("C") & "," & currCd.inventory & "," & _ currCd.sold & "," & currCd.revenues) End Sub Private Sub getCD(ByVal currStr As String, ByRef currCD As cd) currStr = inpf.ReadLine() ' all of the following assumes input file in correct format - title,artist,price,inventory Dim commapos As Integer commapos = currStr.IndexOf(",") currCD.title = currStr.Substring(0, commapos) currStr = currStr.Substring(commapos + 1) commapos = currStr.IndexOf(",") currCD.artist = currStr.Substring(0, commapos) currStr = currStr.Substring(commapos + 1) commapos = currStr.IndexOf(",") currCD.price = Convert.ToDouble(currStr.Substring(0, commapos)) currStr = currStr.Substring(commapos + 1) currCD.inventory = Convert.ToInt32(currStr) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If IO.File.Exists("CDs.txt") Then inpf = IO.File.OpenText("CDs.txt") Do While inpf.Peek <> -1 And numCD <= arraySize Dim currLine As String getCD(currLine, CDs(numCD)) CDs(numCD).sold = 0 CDs(numCD).revenues = 0 LstCD.Items.Add(CDs(numCD).title & " " & CDs(numCD).artist & " " & CDs(numCD).price) numCD = numCD + 1 Loop End If End Sub Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click clearText() End Sub Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub BtnBuy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBuy.Click ' when buying - need to update inventory, number sold and revenues arrays Dim chosen As Integer chosen = LstCD.SelectedIndex If chosen >= 0 AndAlso CDs(chosen).inventory > 0 Then 'can sell it CDs(chosen).inventory = CDs(chosen).inventory - 1 CDs(chosen).sold = CDs(chosen).sold + 1 CDs(chosen).revenues = CDs(chosen).revenues + Convert.ToDouble(TxtTotal.Text.TrimStart("$"c).Trim(","c)) ' write to file outpf = IO.File.AppendText("sales.txt") writeSale(CDs(chosen), outpf) outpf.Close() ' clear text boxes and thank buyer MsgBox("thank you, please come again") clearText() Else If chosen < 0 Then MsgBox("please select a CD to buy first") Else MsgBox("Purchase not successful, CD is out of stock") End If End If End Sub Private Sub LstCD_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstCD.SelectedIndexChanged ' get needed info from arrays Dim chosen As Integer chosen = LstCD.SelectedIndex TxtCD.Text = CDs(chosen).title TxtArtist.Text = CDs(chosen).artist TxtPrice.Text = CDs(chosen).price.ToString("c") TxtInv.Text = CDs(chosen).inventory.ToString("n0") Dim tax As Double tax = CDs(chosen).price * taxRate TxtTax.Text = tax.ToString("c") Dim total As Double total = CDs(chosen).price + tax TxtTotal.Text = total.ToString("c") End Sub Private Sub BtnSummary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSummary.Click ' find top seller - by number sold ' and total revenues Dim cnt As Integer Dim maxSold As Integer = 0 Dim maxCDNum As Integer = 0 Dim totalRevenues As Double = 0 For cnt = 0 To numCD - 1 If CDs(cnt).sold > maxSold Then ' new top seller maxSold = CDs(cnt).sold maxCDNum = cnt End If totalRevenues = totalRevenues + CDs(cnt).revenues Next TxtRev.Text = totalRevenues.ToString("C") TxtTop.Text = CDs(maxCDNum).title TxtTopArtist.Text = CDs(maxCDNum).artist End Sub Private Sub BtnInv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnInv.Click ' sord array by inventory and refresh list box of cds sortCDsNRefreshList(CDs, numCD) ' clear previous inventory list LstInv.Items.Clear() Dim cnt As Integer ' show inventory for all cds For cnt = 0 To numCD - 1 Dim curr As String curr = CDs(cnt).title & " " & CDs(cnt).artist & " " & CDs(cnt).inventory LstInv.Items.Add(curr) Next End Sub Private Sub BtnInClass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnInClass.Click Dim totalRevenues As Double Dim highestSales As Integer = -1 Dim highestTitle As String Dim highestArtist As String Dim cnt As Integer For cnt = 0 To numCD - 1 totalRevenues = totalRevenues + CDs(cnt).revenues If CDs(cnt).sold >= highestSales Then ' we have a new highest seller highestSales = CDs(cnt).sold highestTitle = CDs(cnt).title highestArtist = CDs(cnt).artist Else End If Next cnt TxtRev.Text = totalRevenues.ToString("c") TxtTop.Text = highestTitle TxtTopArtist.Text = highestArtist End Sub End Class